<script setup>
import { listProjectTypeService } from '@/api/project.js'
import { ref } from 'vue'

defineProps({
  modelValue: {
    type: [Number, String]
  },
  width: {
    type: String
  }
})
const emit = defineEmits(['update:modelValue'])
const projectTypeList = ref([])

// 获取所有服务项目类型
const getProjectTypeList = async () => {
  const res = await listProjectTypeService()
  // 提取id和name字段
  projectTypeList.value = res.data.data.map((projectType) => ({
    id: projectType.id,
    name: projectType.name
  }))
}
getProjectTypeList()
</script>

<template>
  <el-select
    :modelValue="modelValue"
    @update:modelValue="emit('update:modelValue', $event)"
    :style="{ width }"
  >
    <el-option
      v-for="projectType in projectTypeList"
      :key="projectType.id"
      :label="projectType.name"
      :value="projectType.id"
    ></el-option>
  </el-select>
</template>
